import pygame, math
from random import *
import particles, resource_manager, ship, game

class Viper(ship.Ship):
    ACC = 0.1
    MAX_SPEED = 8
    TURN = 5
    _image = resource_manager.load_image('viper.png')[0]
    def __init__(self, controller = None):
        self.rect = self._image.get_rect()
        ship.Ship.__init__(self, controller)
        self.next_sec = 60
    
    def update(self, delta):
        ship.Ship.update(self, delta)
        if(self.next_sec < 60):
            self.next_sec += 0.1
    
    def fire_prim(self, delta = 1): # primary fire
        if(pygame.time.get_ticks() > self.next_prim):
            b_speed = (self.speed[0] + (15 * math.cos(math.radians(self.heading))),\
                       self.speed[1] + (15 * math.sin(math.radians(self.heading))))
            
            f = math.radians(self.heading - 20)            
            p1 = (self.position[0] + (15 * math.cos(f)),\
                  self.position[1] + (15 * math.sin(f)))
            
            f = math.radians(self.heading + 20)
            p2 = (self.position[0] + (15 * math.cos(f)),\
                  self.position[1] + (15 * math.sin(f)))
            
            ship.Bullet(self, b_speed, p1)
            ship.Bullet(self, b_speed, p2)
            self.next_prim = pygame.time.get_ticks() + 150

    def fire_sec(self, delta = 1): # secondary fire is speed burst
        #if(self.next_sec > 0):
        if(1):
            self.next_sec -= 1;
            #if(self.next_sec > 5):
            if(1):
                fx = self.ACC * 10 * math.cos(math.radians(self.heading))
                fy = self.ACC * 10 * math.sin(math.radians(self.heading))
                
                p = particles.SmokeParticle((self.position[0] - fx * 10,\
                                             self.position[1] - fy * 10),\
                                            (0.5 + random(), 0.5 + random()),\
                                            randint(-10, 10),  0.2, 1, 100)
                game.particles.add(p)
                
                self.speed[0] += fx
                self.speed[1] += fy
    def hit(self, by):
        pass
    
    def killed(self, by):
        pass